﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace NhaSachDAO
{
    public class NhanVien
    {
        public static DataTable LoadNhanVien()
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cnd = new SqlCommand("select * from NhanVien", cnn);
            cnd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(cnd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
        public static void XoaNhanVien(int manv)
        {
                SqlConnection cnn = SQLconnection.Hamketnoi();
                SqlCommand cmd = new SqlCommand("DELETE FROM NhanVien WHERE (MaNV = " + manv + ")", cnn);
                cmd.CommandType = CommandType.Text;
                cnn.Open();
                cmd.ExecuteNonQuery();
                cnn.Close();
        }
        public static void ThemNhanVien(int manv,string hotennv, string gioitinh,DateTime ngaysinh, string diachi,string cmnd,string sotaikhoan,string chucvu, string catruc,string sdt,string email,float luongnv)
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cmd= new SqlCommand("Insert into NhanVien(MaNV,HoTenNV,GioiTinh,NgaySinh,DiaChi,CMND,SoTaiKhoan,ChucVu,CaTruc,SoDienThoai,Email,LuongNV) Values ("+manv+",N'"+hotennv+"',N'"+gioitinh+"',N'"+ngaysinh+"',N'"+diachi+"',N'"+cmnd+"',N'"+sotaikhoan+"',N'"+chucvu+"',N'"+catruc+"',N'"+sdt+"',N'"+email+"',N'"+luongnv+"')",cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        public static void CapNhatNhanVien(int manv, string hotennv, string gioitinh,DateTime ngaysinh ,string diachi, string cmnd, string sotaikhoan, string chucvu,string sdt)
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cmd = new SqlCommand("Update NhanVien set MaNV="+manv+",HoTenNV=N'"+hotennv+"',GioiTinh=N'"+gioitinh+"',NgaySinh=N'"+ngaysinh+"',DiaChi=N'"+diachi+"',CMND=N'"+cmnd+"',SoTaiKhoan=N'"+sotaikhoan+"',ChucVu=N'"+chucvu+"',SoDienThoai=N'"+sdt+"' Where (MaNV="+manv+")", cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
    }
}
